<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>查询订单</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" href="css/fontastic.css">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="css/custom.css">
    <!-- Favicon-->
    <link rel="shortcut icon" href="img/favicon.ico">
    <script src="vendor/jquery/jquery.js"></script>
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
</head>

<script>
    $(function () {
        //存储这次查询获取的数据
        var orderListData;

        var page = 0;
        var pageSize = 5;

        //生产工艺制定基础数据
        var ptGoodsInfo;

        //生产任务制定基础数据
        var prodTaskGoodsInfo;

        //发放原材料基础数据
        var sendRMInfo;

        var currentOrderId;

        //时间转换
        function getLocalTime(nS) {
            return new Date(parseInt(nS) ).toLocaleString().replace(/:\d{1,2}$/,' ');
        }
        //下一页点击事件添加
        $("#orderListPageDown").click(function () {
            page++;
            $("#searchOrderBtn").click();
        })

        //上一页点击事件添加
        $("#orderListPageup").click(function () {
            if (page > 0) {
                page --;
            }
            $("#searchOrderBtn").click();
        })
        function orderStatusConvert(status){
            switch (status) {
                case 0:
                    return "制定生产工艺";
                case 1:
                    return "制定生产计划";
                case 2:
                    return "分配生产任务";
                case 3:
                    return "发放原材料";
                case 4:
                    return "加工品入库/原材料返回";
                case 5:
                    return "印染半成品";
                case 6:
                    return "成品入库";
                case 7:
                    return "完成订单";
                case 8:
                    return "此订单已完成";
            }
        }

        $("#saveSendRMBtn").click(function () {
            var tasks;
            //console.log($("#addRM" + index).val())
            for (var index in sendRMInfo){
                if ($("#addRM" + index).val() == undefined || $("#addRM" + index).val() == "") {
                    sendRMInfo[index].raisePercent = 0;
                } else {
                    sendRMInfo[index].raisePercent = $("#addRM" + index).val();
                }
            }
            console.log(sendRMInfo);
            $.ajax({
                url: "/erp/prodtask/add/tasks",
                dataType:"json",
                type:"POST",
                data:JSON.stringify(sendRMInfo),
                contentType:"application/json",
                //请求成功回调此函数，data为返回的数据
                success:function (data) {
                    console.log(data);
                    if (data.code != 200) {
                        alert(data.data)
                    } else {
                        //重置表格数据
                        alert("原材料发放成功")
                    }

                    $("#sendRM").empty();
                    $("#sendRMBtnClose").click();
                    $("#searchOrderBtn").click();
                }
            })
        })

        $("#saveMPTBtn").click(function () {
            console.log(JSON.parse(ptGoodsInfo.goodInfo));
            var list = JSON.parse(ptGoodsInfo.goodInfo)
            for (let index in list){
                console.log($("#selectedPT"+index).val())
                list[index].pt = $("#selectedPT"+index).val();
            }
            console.log(list)
            //发送ajax请求，将商品详情修改
            $.ajax({
                url: "/erp/order/establishPT",
                dataType:"json",
                type:"POST",
                data:{"orderId":ptGoodsInfo.id,"ptInfo":JSON.stringify(list)},
                //请求成功回调此函数，data为返回的数据
                success:function (data) {
                    console.log(data);
                    if (data.code != 200) {
                        alert(data.data)
                    } else {
                        //重置表格数据
                        alert("制定生产工艺成功")
                    }

                    $("#mptInfo").empty();
                    $("#mptTableClose").click();
                    $("#searchOrderBtn").click();
                }
            })
        })

        //删除订单（支持多选）
        $("#orderListRemove").click(function () {
            var idArray = [];
            console.log($("input:checked"));
            //选取选中的CheckBox，并循环遍历，将ID加入到idArray中
            $("input:checked").each(function () {
                idArray.push($(this).attr("id").substring(5));
            })

            //Ajax发送到后台删除
            $.ajax({
                url: "/erp/order/list/delete",
                dataType:"json",
                type:"POST",
                data:{"idArray":idArray},
                //请求成功回调此函数，data为返回的数据
                success:function (data) {
                    console.log(data);
                    if (data.code != 200) {
                        alert(data.data)
                    } else {
                        //重置表格数据
                        $("#searchOrderBtn").click();
                        alert("删除成功");
                    }
                }
            })
        })

        function PTListOption(id){
            //通过产品id查询对应的生产工艺
            var ptNames;
            $.ajax({
                    url: "/erp/pt/list/" + id,
                    dataType: "json",
                    type: "GET",
                    data: {},
                    async: false,
                    success: function (data) {
                        console.log(data)
                        if (data.code == 200){
                            ptNames = data.data;
                        }
                    }
                }
            )
            let optionName = "";
            for (let index in ptNames) {
                optionName += "<option>" + ptNames[index] + "</option>";
            }
            return optionName;

        }

        function OEListOption(){
            //通过产品id查询对应的外协企业
            var oeNames;
            $.ajax({
                    url: "/erp/coo/list",
                    dataType: "json",
                    type: "GET",
                    data: {},
                    async: false,
                    success: function (data) {
                        console.log(data)
                        if (data.code == 200){
                            oeNames = data.data;
                        }
                    }
                }
            )
            var optionOEName = "";
            for (var index in oeNames) {
                optionOEName += "<option>" + oeNames[index].name + "</option>";
            }
            return optionOEName;

        }

        function generatePTTable(data) {
            $("#mptInfo").empty();
            var list = JSON.parse(data.goodInfo);
            for (var index in list){
                //生成基础表格
                $("#mptInfo").append("<tr>" +
                    "<td>" + list[index].goods.goodName+"</td>"+
                    "<td>" + list[index].goodsNumber+"</td>"+
                    "<td>" + list[index].goodsUnit+"</td>"+
                    "<td>" +
                        "<select id='selectedPT"+ index +"' class='form-control'>" +
                        PTListOption(list[index].goods.id)+
                    "</select>" +
                    "</td>" +
                    "</tr>"
                );
            }
        }



        function generateProdTask(data) {
            $("#assignTask").empty();
            var list = JSON.parse(data.goodInfo);
            console.log(list)
            for (var index in list) {
                $("#assignTask").append("<tr>"+
                    "<td>" + list[index].goods.id+"</td>"+
                    "<td>" + list[index].goods.goodName+"</td>"+
                    "<td>" + list[index].goodsNumber+ list[index].goodsUnit+"</td>"+
                    "<td>" + list[index].pt+"</td>"+
                    "<td>" + data.id+"</td>"+
                    "<td>" +
                    "<select id='selectedOE"+ index +"' class='form-group'>"+
                    OEListOption()+
                    "</select>"+
                    "</td>"+
                    "</tr>"
                )
            }
            prodTaskGoodsInfo = data;
        }


        function generateSendRM(data){
            $("#sendRM").empty();
            var list = data;
            for (var index in list){
                $("#sendRM").append("<tr>"+
                    "<td>" + list[index].goodsId+"</td>"+
                    "<td>" + list[index].goodsName+"</td>"+
                    // "<td>" + "</td>"+
                    "<td>" + list[index].ptName +"</td>"+
                    "<td>" + list[index].orderId +"</td>"+
                    "<td>" + list[index].cooperativesName +"</td>"+
                    "<td>"+
                        "<input placeholder='可不填（默认最低发放量）' id='addRM"+index+"' class='form-group'>"+
                    "</td>"+
                    "</tr>"

                )
            }
            sendRMInfo = data;

        }

        //分配生产任务模态框保存按钮点击事件
        $("#saveAssignTaskBtn").click(function () {
            console.log(prodTaskGoodsInfo);
            var list = JSON.parse(prodTaskGoodsInfo.goodInfo);

            var count = 0;
            for (var index in list) {
                var obj = {};
                obj.cooperativesName  = $("#selectedOE"+index).val();
                obj.orderId = prodTaskGoodsInfo.id;
                obj.goodsId = list[index].goods.id;
                obj.goodsName = list[index].goods.goodName;
                obj.ptName = list[index].pt;
                obj.taskStatus = 0;
                //console.log(obj)
                $.ajax({
                        url: "/erp/prodtask/add",
                        dataType: "json",
                        type: "POST",
                        data: obj,
                        async: false,
                        success: function (data) {
                            console.log(data)
                            if (data.code == 200){
                                console.log("添加成功");
                                count++;
                            }
                        }
                    }
                )
            }
            console.log(count == list.length)
            if (count == list.length) {
                $.ajax({
                        url: "/erp/order/status/"+3,
                        dataType: "json",
                        data:{"id": prodTaskGoodsInfo.id},
                        type: "POST",
                        success: function (data) {
                            if (data.code != 200){
                                count = 0;
                            }
                        }
                    }
                )
                if (count == list.length) {
                    alert("生产任务 "+count+" 条添加成功");
                }
            }
            $("#searchOrderBtn").click();
            $("#assignTaskTableClose").click();
        })




        function generateGoodsInfoTable(data) {
            console.log(data);
            $("#goodsInfo").empty();
            var list = JSON.parse(data.goodInfo);
            console.log(list)
            for(var index in list){
                $("#goodsInfo").append("<tr>"+
                    "<td>" + list[index].goods.goodName+"</td>"+
                    "<td>" + list[index].goodsNumber+"</td>"+
                    "<td>" + list[index].goodsUnit+"</td>"+
                    "</tr>"
                )
            }
        }

        function disableBtn(data){
            if (data == 8) {
                return "disabled";
            }
        }


        function generateTable(data) {
            $("#searchOrderTable").append("<thead>"+
                "<tr>" +
                "<th valign=middle align=center></th>" +
                "<th valign=middle align=center >ID</th>" +
                "<th valign=middle align=center>客户名</th>" +
                "<th valign=middle align=center>承办人</th>" +
                "<th valign=middle align=center>联系方式</th>"+
                "<th valign=middle align=center>送货地址</th>"+
                "<th valign=middle align=center>订单开始时间</th>"+
                "<th valign=middle align=center>结束时间</th>"+
                "<th valign=middle align=center>商品详情</th>"+
                "<th valign=middle align=center>订单状态</th>"+
                "<th valign=middle align=center>下一步</th>"+
                "</tr>" +
                "</thead>");
            //根据数据绘制order表格并添加事件监听
            for (var i = 0; i < data.data.length; i++) {
                //为order订单添加表头
                $("#searchOrderTable").append("<tr>"+
                    "<td>"+
                    "<input id='order"+ data.data[i].id + "' type='checkbox'>"+
                    "</td>"+
                    "<td>"+
                    data.data[i].id+
                    "</td>"+
                    "<td>"+
                    data.data[i].customerName+
                    "</td>"+
                    "<td>"+
                    data.data[i].client+
                    "</td>"+
                    "<td>"+
                    data.data[i].buyerPhoneNumber+
                    "</td>"+
                    "<td>"+
                    data.data[i].buyerAddress+
                    "</td>"+
                    "<td>"+
                    getLocalTime(data.data[i].orderStartTime)+
                    "</td>"+
                    "<td>"+
                    data.data[i].orderFinishTime+
                    "</td>"+
                    "<td>"+
                    "<button type=\"button\" data-toggle=\"modal\" data-target=\"#orderModal\" class=\"btn btn-secondary \" id='viewGoods"+ data.data[i].id +"'>查看</button>"+
                    "</td>"+
                    "<td>"+
                    data.data[i].orderStatus+
                    "</td>"+
                    "<td>"+
                        "<button "+disableBtn(data.data[i].orderStatus)+" type='button' class='btn btn-link' id='nextOperation"+ data.data[i].id + "'>"+orderStatusConvert(data.data[i].orderStatus)+"</button>"+
                    "</td>"+
                    "</tr>"
                );

                //为查看商品详情按钮添加点击事件
                $("#viewGoods" + data.data[i].id).click(function () {
                    //生成商品详情表格
                    console.log(orderListData)
                    //获取要查看商品详情的id
                    var currentId = $(this).attr("id").substring(9);
                    console.log(currentId);
                    for (var temp in orderListData.data) {
                        if (orderListData.data[temp].id == currentId){
                            //生成表格
                            $("#goodsInfo").empty();
                            generateGoodsInfoTable(orderListData.data[temp]);
                            return;
                        }
                    }
                })

                function printAndDyeEnterpriseOption(){
                    //通过产品id查询对应的印染企业
                    var oeNames;
                    $.ajax({
                            url: "/erp/pdenterprise/list",
                            dataType: "json",
                            type: "GET",
                            async: false,
                            success: function (data) {
                                console.log(data)
                                if (data.code == 200){
                                    oeNames = data.data;
                                }
                            }
                        }
                    )
                    var optionOEName = "";
                    for (var index in oeNames) {
                        optionOEName += "<option>" + oeNames[index].enterpriseName + "</option>";
                    }
                    return optionOEName;

                }

                function generatePrintingAndDyeingBody(list) {
                    for (var index in list) {
                        $("#printingAndDyeingBody").append("<tr>" +
                            "<td>"+ list[index].processedGoodsId+"</td>" +
                            "<td>"+ list[index].processedGoodsName+"</td>" +
                            "<td>"+ list[index].orderId +"</td>" +
                            "<td>"+ list[index].count+"</td>" +
                            "<td>"+ list[index].unit+"</td>" +
                            "<td> <select id='printDye"+index+"'>" + printAndDyeEnterpriseOption() + "</select></td>" +
                            "</tr>")
                    }
                }
                function taskStatusConvert(status) {
                    if (status == 0) {
                        return "<option value='1'>完成</option><option value='0' selected>未完成</option>";
                    }else if (status == 1) {
                        return "<option value='1' selected>完成</option><option value='0'>未完成</option>";
                    }
                }

                function disableSelect(data) {
                    if (data == 1){
                        return "disabled";
                    }
                    return "";
                }
                function generatePrintingAndDyeingTaskTable(list){
                    $("#printingAndDyeingTaskTableBody").empty();
                    for (var index in list) {
                        $("#printingAndDyeingTaskTableBody").append("<tr>" +
                                "<td>" +  list[index].goodsId + "</td>" +
                                "<td>" +  list[index].goodsName + "</td>" +
                                "<td>" +  list[index].orderId + "</td>" +
                                "<td>" +  list[index].count + "</td>" +
                                "<td>" +  list[index].unit + "</td>" +
                                "<td>" +  list[index].printAndDyeEnterpriseName + "</td>" +
                                "<td>" +  getLocalTime(list[index].createTime) + "</td>" +
                                // "<td>" +  taskStatusConvert(list[index].taskStatus) + "</td>" +
                                "<td><select "+ disableSelect(list[index].taskStatus) +" id='status"+index+"'>"+ taskStatusConvert(list[index].taskStatus)+"</select></td>"+
                        "</tr>");
                    }
                }


                function generateReturnRMTable(data){
                    $("#returnRM").empty();
                    for (var index in data)  {
                        $("#returnRM").append(
                            "<tr>" +
                            "<td valign=middle align=center>"+data[index].id+"</td>" +
                            "<td valign=middle align=center>"+data[index].name+"</td>" +
                            "<td valign=middle align=center>"+data[index].type+"</td>" +
                            "<td valign=middle align=center>"+data[index].cooperativesName+"</td>" +
                            "<td valign=middle align=center>"+"<input placeholder='可不填（默认为0）' id='returnCount"+index+"'/>"+"</td>" +
                            "<td valign=middle align=center> <select id='returnAddress" + index + "'><option value='self'>返回到原仓库</option><option value='other'>外协企业留存</option> </select></td>"
                            )
                    }

                }
                var pdTasks;
                $("#comfirmPDInventory").off().on('click',function () {
                    for (var index in pdTasks) {
                        pdTasks[index].taskStatus = $("#status"+index).val();
                    }
                    console.log(pdTasks);
                    $.ajax({
                            url: "/erp/prodPrintDye/list/save1",
                            dataType: "json",
                            data:JSON.stringify(pdTasks),
                            async: false,
                            type: "POST",
                            contentType:"application/json",
                            success: function (data) {
                                if (data.code == 200){
                                    //console.log()
                                    alert("印染任务保存成功")
                                    $("#PDListCloseBtn").click();
                                    $("#searchOrderBtn").click();
                                } else {
                                    alert(data.data)
                                }
                            }
                        }
                    )
                })
                
                var rmList;
                $("#savereturnRMBtn").off().on('click',function () {
                    console.log(rmList)
                    // console.log("click")


                    for (var index in rmList) {
                        if ($("#returnCount" + index).val()==undefined || $("#returnCount" + index).val() == ""){
                            rmList[index].returnRMCount = 0;
                        } else {
                            rmList[index].returnRMCount = $("#returnCount" + index).val();
                        }
                        rmList[index].returnAddress = $("#returnAddress"+index).val();
                        rmList[index].orderId = currentOrderId;
                    }

                    console.log(rmList)
                    $.ajax({
                            url: "/erp/rmInventory/list/save",
                            dataType: "json",
                            data:JSON.stringify(rmList),
                            async: false,
                            type: "POST",
                            contentType:"application/json",
                            success: function (data) {
                                if (data.code == 200){
                                    alert("加工品入库成功,原材料返回成功")
                                    $("#searchOrderBtn").click();
                                } else {
                                    alert(data.data)
                                }
                            }
                        }
                    )

                    $("#returnRM").empty();
                    $("#returnRMBtnClose").click();
                })
                var currentProcessedProduction;

                $("#savePrintingAndDyeingBtn").off().on('click',function () {
                    console.log(currentProcessedProduction)
                    for (var index in currentProcessedProduction) {
                        currentProcessedProduction[index].printAndDyeEnterpriseName = $("#printDye"+index).val();
                    }
                    //发送到后端保存
                    $.ajax({
                        url: "/erp/prodPrintDye/list/save",
                        dataType:"json",
                        type:"POST",
                        contentType:"application/json",
                        data:JSON.stringify(currentProcessedProduction),
                        //请求成功回调此函数，data为返回的数据
                        success:function (data) {
                            if (data.code == 200) {
                                alert("半成品加入印染成功");
                                $("#printingAndDyeingClose").click();
                                $("#searchOrderBtn").click();
                            } else {
                                alert(data.data);
                            }
                        }
                    })
                    console.log(currentProcessedProduction);
                });


                
                $("#nextOperation" + data.data[i].id).off().on('click',function () {
                    //生成下一步操作
                    console.log(orderListData)
                    //获取要查看商品详情的id
                    currentOrderId = $(this).attr("id").substring(13);
                    //遍历循环得到当前需要操作的订单
                    for (var temp in orderListData.data) {
                        if (orderListData.data[temp].id == currentOrderId){
                            if (orderListData.data[temp].orderStatus == 0){
                                //生成制定生产工艺表格
                                console.log("制定生产工艺")
                                // 将表格数据清空
                                $("#mptInfo").empty();
                                console.log(orderListData.data[temp]);
                                ptGoodsInfo = orderListData.data[temp];
                                generatePTTable(ptGoodsInfo);
                                //显示制定生产工艺模态框
                                $("#displayMPTModals").click();
                                return;
                            }
                            if (orderListData.data[temp].orderStatus == 1){
                                $.ajax({
                                    url: "/erp/order/makeprodplan",
                                    dataType:"json",
                                    type:"POST",
                                    data:{"orderId":orderListData.data[temp].id},
                                    //请求成功回调此函数，data为返回的数据
                                    success:function (data) {
                                        var message = "";
                                        console.log(data);
                                        if (data.data){
                                            for (var index in data.data){
                                                message = message + data.data[index]+ "\n";
                                            }
                                            alert(message);
                                            $("#searchOrderBtn").click()
                                        }
                                    }
                                })
                                return;
                            }
                            if(orderListData.data[temp].orderStatus == 2){
                                console.log("分配生产任务")
                                //清空表格
                                $("#assignTask").empty();
                                //console.log(orderListData.data[temp]);
                                ptGoodsInfo = orderListData.data[temp];
                                generateProdTask(ptGoodsInfo);
                                $("#assignTaskModals").click();
                                return;
                            }

                            if (orderListData.data[temp].orderStatus == 3){
                                console.log("根据生产任务发放原材料");
                                //清空表格
                                $("#sendRM").empty();
                                ptGoodsInfo = orderListData.data[temp];
                                //根据订单id查询生产任务，对每条生产任务分配原材料
                                $.ajax({
                                        url: "/erp/prodtask/list",
                                        dataType: "json",
                                        data:{"orderId": ptGoodsInfo.id},
                                        type: "GET",
                                        success: function (data) {
                                            console.log(data)
                                            if (data.code == 200)
                                            generateSendRM(data.data);
                                        }
                                    }
                                )

                                $("#sendRawMaterial").click();
                                return;
                            }

                            if (orderListData.data[temp].orderStatus == 4)  {
                                console.log("加工品入库，原材料返回");
                                console.log(orderListData.data[temp])
                                //根据订单ID 获取原材料列表 展示到表格
                                $.ajax({
                                        url: "/erp/order/rm/list",
                                        dataType: "json",
                                        data:{"orderId": currentOrderId},
                                        type: "GET",
                                        async:false,
                                        success: function (data) {
                                            rmList = data.data;
                                            console.log(data);
                                            generateReturnRMTable(data.data);
                                            $("#returnRawMaterial").click();
                                        }
                                    }
                                )
                            }
                            if (orderListData.data[temp].orderStatus == 5)  {
                                console.log("加工品进入印染");
                                console.log(orderListData.data[temp])
                                //根据订单ID 获取原材料列表 展示到表格
                                $.ajax({
                                        url: "/erp/processedProdStock/list",
                                        dataType: "json",
                                        data:{"orderId": currentOrderId},
                                        type: "GET",
                                        success: function (data) {
                                            console.log(data);
                                            if (data.code == 200) {
                                                currentProcessedProduction = data.data;
                                                generatePrintingAndDyeingBody(data.data);
                                                $("#printingAndDyeingModalBtn").click();
                                            } else  {
                                                alert(data.data)
                                            }

                                        }
                                    }
                                )
                            }

                            if (orderListData.data[temp].orderStatus == 6)  {
                                console.log("成品入库");
                                //console.log(orderListData.data[temp])
                                //根据订单ID 获取印染任务列表 展示到表格
                                $.ajax({
                                        url: "/erp/prodPrintDye/list/"+currentOrderId,
                                        dataType: "json",
                                        type: "GET",
                                        success: function (data) {
                                            console.log(data);
                                            if (data.code == 200) {
                                                console.log(data)
                                                pdTasks = data.data;
                                                generatePrintingAndDyeingTaskTable(data.data);
                                                $("#PDTaskBtn").click();
                                                // $("#printingAndDyeingModalBtn").click();
                                            } else  {
                                                alert(data.data)
                                            }

                                        }
                                    }
                                )
                            }

                            if (orderListData.data[temp].orderStatus == 7)  {
                                console.log("成品出库，订单完成");

                                //根据订单ID，成品出库并完成订单状态
                                $.ajax({
                                        url: "/erp/finishedGoodsInven/success",
                                        dataType: "json",
                                        data:{"orderId": currentOrderId},
                                        type: "POST",
                                        success: function (data) {
                                            if (data.code = 200) {
                                                alert("成品已出库，交易完成！")
                                                $("#searchOrderBtn").click();
                                            } else {
                                                alert(data.data)
                                            }

                                        }
                                    }
                                )
                            }

                        }
                    }

                })
            }
        }
        
        
        
        //查询
        $("#searchOrderBtn").click(function () {

            //判断是否模糊查询
            var name = $("#searchOrderText").val();
            //console.log("name"+name);
            if(name != "") {
                //ajax获取后台数据，模糊查询
                $.ajax({
                    url: "/erp/order/list/name/"+page+"/"+pageSize,
                    dataType:"json",
                    type:"GET",
                    data:{"name":name},
                    //请求成功回调此函数，data为返回的数据
                    success:function (data) {
                        console.log(data);
                        //判断返回数据，若为空，则说明下一页无数据，重置page的值
                        if (data.code == 400) {
                            alert("无相关订单信息");
                            if (page > 0) {
                                page--;
                            }
                            return;
                        } else {
                            orderListData = data;
                            $("#searchOrderTable").empty();
                            generateTable(data);
                        }

                    }
                })
                return;
            }

            //从后台获取产品列表
            $.ajax({
                url: "/erp/order/list/"+page+"/"+pageSize,
                dataType:"json",
                type:"GET",
                //请求成功回调此函数，data为返回的数据
                success:function (data) {
                    console.log(data);
                    //判断返回数据，若为空，则说明下一页无数据，重置page的值
                    if (data.code == 400) {
                        alert("无相关产品信息")
                        if (page > 0) {
                            page--;
                        }
                        return;
                    } else {
                        orderListData = data;
                        //console.log(goodsListData);
                        $("#searchOrderTable").empty();
                        generateTable(data);
                    }
                }
            })
        })

        //新建商品信息
        $("#saveNewGoodsBtn").click(function () {
            console.log("click");
            var name = $("#newGoodsName").val();
            var weight = $("#kgUnit").val();
            var piece = $("#pieceUnit").val();
            console.log(name + weight + piece)

            $.ajax({
                url:"/erp/goods/add",
                type:"POST",
                dataType:"json",
                data:{"goodName":name,"weightPrize":weight,"piecePrize":piece},
                success:function (data) {
                    console.log(data)
                    if (data.code == 200){
                        alert("新建产品成功")
                    } else{
                        alert(data.data)
                    }
                    $("#newGoodsName").val("");
                    $("#kgUnit").val("");
                    $("#pieceUnit").val("");
                    //关闭模态框
                    $("#newGoodsClose").click();

                }
            })
        })


    })

</script>

<body>
<div class="page">
    <!-- Main Navbar-->
    <header class="header">
        <nav class="navbar">
            <!-- Search Box-->
            <div class="search-box">
                <button class="dismiss"><i class="icon-close"></i></button>
                <form id="searchForm" action="#" role="search">
                    <input type="search" placeholder="What are you looking for..." class="form-control">
                </form>
            </div>
            <div class="container-fluid">
                <div class="navbar-holder d-flex align-items-center justify-content-between">
                    <!-- Navbar Header-->
                    <div class="navbar-header">
                        <!-- Navbar Brand --><a href="index.html" class="navbar-brand d-none d-sm-inline-block">
                        <div class="brand-text d-none d-lg-inline-block"><strong>子恒针erp</strong></div>
                                            </a>

                        <!-- Toggle Button--><a id="toggle-btn" href="#" class="menu-btn active"><span></span><span></span><span></span></a>
                    </div>
                    <!-- Navbar Menu -->

                </div>
            </div>
        </nav>
    </header>
    <div class="page-content d-flex align-items-stretch">
        <!-- Side Navbar -->
        <nav class="side-navbar">

            <!-- Sidebar Navidation Menus-->
            <ul class="list-unstyled">

                <li ><a href="#producedropdownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i><font color="black" size="3.8"> <strong>生产管理</strong></font></a>
                    <ul id="producedropdownDropdown" class="collapse list-unstyled ">
                        <li ><a href="#orderDropdown" aria-expanded="false" data-toggle="collapse"><font color=black size="3"><strong> 订单管理</strong></font></a>
                            <ul id="orderDropdown" class="collapse list-unstyled ">
                                <li ><a href="addOrder.html">&nbsp;&nbsp;&nbsp;&nbsp;新增订单</a></li>

                                <li><a href="#">&nbsp;&nbsp;&nbsp;&nbsp;<u>查询订单</u></a></li>
                            </ul>
                        </li>

                        <li><a href="searchGoods.html"><font color="#626262" size="3"><strong>产品管理</strong></font></a>

                        </li>

                        <li><a href="manageCustomer.html"><font color="#626262" size="3"><strong>客户管理</strong></font></a>

                        </li>

                        <li><a href="#processDropdown" aria-expanded="false" data-toggle="collapse"><font color="#626262" size="3"><strong>生产工艺管理</strong></font></a>
                            <ul id="processDropdown" class="collapse list-unstyled ">
                                <li><a href="makeProductionTechnology.html">&nbsp;&nbsp;&nbsp;&nbsp;新增生产工艺</a></li>
                                <li><a href="manageProductionTechnology.html">&nbsp;&nbsp;&nbsp;&nbsp;查询生产工艺</a></li>
                            </ul>
                        </li>

                        <li><a href="manageOutsourcingEnterprise.html"><font color="#626262" size="3"><strong>外协企业管理</strong></font></a>

                    </ul>
                </li>

                <!--库存管理-->
                <li ><a href="#stockdropdownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i><font  size="3.8"> <strong>库存管理</strong></font></a>
                    <ul id="stockdropdownDropdown" class="collapse list-unstyled ">
                        <li><a href="manageSupplier.html" ><font color="#626262" size="3"><strong>供应商关系管理</strong></font></a>

                        </li>

                        <li><a href="manageRawMaterial.html" ><font color="#626262" size="3"><strong>原材料信息管理</strong></font></a>

                        </li>

                        <li><a href="manageRMInventory.html" ><font color="#626262" size="3"><strong>原材料库存管理</strong></font></a>
                        </li>

                        <li><a href="managePDenterprise.html" ><font color="#626262" size="3"><strong>印染企业管理</strong></font></a>
                        </li>

                        <li><a href="manageOutsourcingRMInventory.html" ><font color="#626262" size="3"><strong>外协企业原材料管理</strong></font></a>
                        </li>

                        <li><a href="manageFinishedGoods.html" ><font color="#626262" size="3"><strong>成品库存管理</strong></font></a>
                        </li>

                    </ul>
                </li>

            </ul>
        </nav>

        <div class="content-inner">
            <!-- Page Header-->
            <header class="page-header">
                <div class="container-fluid">
                    <h2 class="no-margin-bottom">查询订单</h2>
                </div>
            </header>
            <!-- Breadcrumb-->
            <section>
                <div>
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header d-flex align-items-center">
                                <h3 class="h4"></h3>
                            </div>

                            <div class="card-body">
                                <form class="form-order">

                                    <div class="form-group row">
                                        <label class="col-lg-2 form-control-label no-padding-bottom container-fluid text-center"><font size="3.5"> 客户名称：</font></label>
                                        <div class="col-lg-8 ">
                                            <div class="input-group">
                                                <input type="text" class="form-control" id="searchOrderText">
                                                <!--<div class="input-group-btn">-->
                                                    <!--<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="orderNameBtn">-->
                                                    <!--</button>-->
                                                    <!--<ul class="dropdown-menu pull-right " id="orderNameList">-->

                                                    <!--</ul>-->
                                                <!--</div>&lt;!&ndash; /btn-group &ndash;&gt;-->
                                            </div><!-- /input-group -->
                                        </div><!-- /.col-lg-10 -->
                                        <button type="button"  class="btn btn-primary col-lg-2 " id="searchOrderBtn">查询</button>
                                    </div>

                                </form>

                                <div class="form-group row">
                                    <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                    <a class='btn btn-primary ' href="addOrder.html">新增订单</a>
                                    <!--<button type="button" data-toggle="modal" class="btn btn-primary ">新增</button>-->

                                    <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                    <button type="button" class="btn btn-secondary" id="orderListRemove">删除</button>
                                    <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                    <button type="button" class="btn btn-secondary" id="orderListPageup">上一页</button>

                                    <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                    <button type="button" class="btn btn-secondary" id="orderListPageDown">下一页</button>



                                </div>

                                <table class="table table-striped table-sm" id="searchOrderTable">
                                    <thead>
                                    <tr>
                                        <th valign=middle align=center ></th>
                                        <th valign=middle align=center >ID</th>
                                        <th valign=middle align=center>公司名称</th>
                                        <th valign=middle align=center>承办人</th>
                                        <th valign=middle align=center>联系方式</th>
                                        <th valign=middle align=center>送货地址</th>
                                        <th valign=middle align=center>订单开始时间</th>
                                        <th valign=middle align=center>结束时间</th>
                                        <th valign=middle align=center>商品详情</th>
                                        <th valign=middle align=center>订单当前状态</th>
                                        <th valign=middle align=center>下一步</th>
                                    </tr>
                                    </thead>

                                </table>

                            </div>

                        </div>
                    </div>
                </div>
            </section>
            <!--查看商品详情模态框-->
            <div id="orderModal" tabindex="-1" role="dialog" aria-labelledby="orderModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 id="orderModalLabel" class="modal-title">产品信息列表</h4>

                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>

                        <div class="modal-body">
                            <!--<span>testSpan</span>-->
                            <table class="table table-striped table-sm" id="goodsInfoTable">
                                <thead>
                                    <th valign=middle align=center >产品</th>
                                    <th valign=middle align=center >数量</th>
                                    <th valign=middle align=center >单位</th>
                                </thead>
                                <tbody id="goodsInfo">
                                </tbody>
                            </table>
                        </div>

                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary" >关闭</button>
                            <!--<button type="button" class="btn btn-primary" id="saveNewGoodsBtn">保存</button>-->
                        </div>
                    </div>
                </div>

            </div>

            <button type="button" class="btn btn-link"  data-toggle="modal" data-target="#PDTaskModal" id="PDTaskBtn"></button>
            <!-- 6. 印染任务模态框-->
            <div id="PDTaskModal" tabindex="-1" role="dialog" aria-labelledby="returnRMModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">印染成品入库</h4>

                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>
                        <div class="modal-body">
                            <table class="table table-striped table-sm">
                                <thead>
                                <th valign=middle align=center >印染产品ID</th>
                                <th valign=middle align=center >印染产品名称</th>
                                <th valign=middle align=center >印染产品对应订单</th>
                                <th valign=middle align=center >印染产品数量</th>
                                <th valign=middle align=center >印染产品单位</th>
                                <th valign=middle align=center >印染企业</th>
                                <th valign=middle align=center >任务创建时间</th>
                                <th valign=middle align=center >任务状态</th>
                                </thead>
                                <tbody id="printingAndDyeingTaskTableBody">

                                </tbody>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary" id="PDListCloseBtn">关闭</button>
                            <button type="button" class="btn btn-primary" id="comfirmPDInventory">确认印染入库</button>
                        </div>
                    </div>
                </div>
            </div><!-- 6. 印染任务模态框-->


            <button type="button" class="btn btn-link"  data-toggle="modal" data-target="#printingAndDyeing" id="printingAndDyeingModalBtn"></button>
            <!--5 加工品印染模态框-->
            <div id="printingAndDyeing" tabindex="-1" role="dialog" aria-labelledby="returnRMModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">加工品出库/进入印染</h4>

                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>
                        <div class="modal-body">
                            <table class="table table-striped table-sm">
                                <thead>
                                <th valign=middle align=center >加工品ID</th>
                                <th valign=middle align=center >加工品名称</th>
                                <th valign=middle align=center >加工品对应订单</th>
                                <th valign=middle align=center >加工品数量</th>
                                <th valign=middle align=center >加工品单位</th>
                                <th valign=middle align=center >选择印染企业</th>
                                </thead>
                                <tbody id="printingAndDyeingBody">

                                </tbody>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary" id="printingAndDyeingClose">关闭</button>
                            <button type="button" class="btn btn-primary" id="savePrintingAndDyeingBtn">确认加工品进入印染</button>
                        </div>
                    </div>
                </div>
            </div><!--5 加工品入库/原材料返回模态框-->

            <button type="button" class="btn btn-link"  data-toggle="modal" data-target="#returnRMModal" id="returnRawMaterial"></button>
            <!--4 加工品入库/原材料返回模态框-->
            <div id="returnRMModal" tabindex="-1" role="dialog" aria-labelledby="returnRMModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">加工品入库/原材料返回</h4>

                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>
                        <div class="modal-body">
                            <table class="table table-striped table-sm" id="returnRMTable">
                                <thead>
                                <th valign=middle align=center >原材料ID</th>
                                <th valign=middle align=center >原材料名称</th>
                                <th valign=middle align=center >原材料类型</th>
                                <th valign=middle align=center >对应外协企业</th>
                                <th valign=middle align=center >剩余原材料</th>
                                <th valign=middle align=center >剩余原材料返回地址</th>
                                </thead>
                                <tbody id="returnRM">

                                </tbody>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary" id="returnRMBtnClose">关闭</button>
                            <button type="button" class="btn btn-primary" id="savereturnRMBtn">确认返回原材料且加工品入库</button>
                        </div>
                    </div>
                </div>
            </div><!--4 加工品入库/原材料返回模态框-->


            <button type="button" class="btn btn-link"  data-toggle="modal" data-target="#sendRMModal" id="sendRawMaterial"></button>
            <!--3 发放原材料模态框-->
            <div id="sendRMModal" tabindex="-1" role="dialog" aria-labelledby="sendRMModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">发放原材料</h4>

                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>
                        <div class="modal-body">
                            <table class="table table-striped table-sm" id="sendRMTable">
                                <thead>
                                <th valign=middle align=center >产品ID</th>
                                <th valign=middle align=center >产品名称</th>
                                <th valign=middle align=center >生产工艺名称</th>
                                <th valign=middle align=center >对应订单</th>
                                <th valign=middle align=center >外协企业</th>
                                <th valign=middle align=center >追加原材料（%）</th>
                                </thead>
                                <tbody id="sendRM">
                                </tbody>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary" id="sendRMBtnClose">关闭</button>
                            <button type="button" class="btn btn-primary" id="saveSendRMBtn">确认发放</button>
                        </div>
                    </div>
                </div>
            </div><!--发放原材料模态框-->


            <button type="button" class="btn btn-link"  data-toggle="modal" data-target="#mptModal" id="displayMPTModals"></button>
            <!--制定生产工艺模态框-->
            <div id="mptModal" tabindex="-1" role="dialog" aria-labelledby="mptModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 id="mptModalLabel" class="modal-title">制定生产工艺</h4>

                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>
                        <div class="modal-body">
                            <table class="table table-striped table-sm" id="mptInfoTable">
                                <thead>
                                <th valign=middle align=center >产品</th>
                                <th valign=middle align=center >数量</th>
                                <th valign=middle align=center >单位</th>
                                <th valign=middle align=center >选择生产工艺</th>
                                </thead>
                                <tbody id="mptInfo">
                                </tbody>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary" id="mptTableClose">关闭</button>
                            <button type="button" class="btn btn-primary" id="saveMPTBtn">保存</button>
                        </div>
                    </div>
                </div>
            </div><!--制定生产工艺模态框-->

            <button type="button" class="btn btn-link"  data-toggle="modal" data-target="#assignTaskModal" id="assignTaskModals"></button>
            <!--分配生产任务模态框-->
            <div id="assignTaskModal" tabindex="-1" role="dialog" aria-labelledby="assignTaskModalLabel" aria-hidden="true" class="modal fade text-left">
                <div role="document" class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 id="assignTaskModalLabel" class="modal-title">分配生产任务</h4>

                            <button type="button" data-dismiss="modal" aria-label="Close" class="close"><span aria-hidden="true">×</span></button>
                        </div>
                        <div class="modal-body">
                            <table class="table table-striped table-sm" id="assignTaskTable">
                                <thead>
                                <th valign=middle align=center>产品ID</th>
                                <th valign=middle align=center>产品名称</th>
                                <th valign=middle align=center>数量</th>
                                <th valign=middle align=center>生产工艺名称</th>
                                <th valign=middle align=center>对应订单</th>
                                <th valign=middle align=center>选择外协企业</th>
                                </thead>
                                <tbody id="assignTask">
                                </tbody>
                            </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" data-dismiss="modal" class="btn btn-secondary" id="assignTaskTableClose">关闭</button>
                            <button type="button" class="btn btn-primary" id="saveAssignTaskBtn">保存</button>
                        </div>
                    </div>
                </div>
            </div><!--分配生产任务模态框-->
            <!--测试代码-->



            <!-- Page Footer-->
            <footer class="main-footer">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-6">
                            <p>Your company &copy; 2017-2019</p>
                        </div>

                    </div>
                </div>
            </footer>
        </div>
    </div>
</div>
<!-- JavaScript files-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/popper.js/umd/popper.min.js"> </script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
<script src="vendor/chart.js/Chart.min.js"></script>
<script src="vendor/jquery-validation/jquery.validate.min.js"></script>
<!-- Main File-->
<script src="js/front.js"></script>
</body>
</html>
